package com.maple.soa.util;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author lijian
 * @date 2020/7/4
 */
public class ApplicationContextUtils {
    private static ApplicationContext applicationContext;
    private static ApplicationContextUtils instance;

    static {
        applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        instance = new ApplicationContextUtils();
    }

    public static ApplicationContextUtils getInstance() {
        return instance;
    }

    private ApplicationContext getApplicationContext(String xmlPath) {
        return new ClassPathXmlApplicationContext(xmlPath);
    }

    public <T> T getBean(String name, Class<T> classType) {
        return applicationContext.getBean(name, classType);
    }

    public BeanFactory getBeanFactory() {
        return applicationContext.getParentBeanFactory();
    }

}
